<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

class upload extends CI_Controller {
	public function __construct() {
		parent::__construct ();
		$this->load->helper ( 'form' );
		$this->load->helper ( 'url' );
	}
	
	public function index() {
		$this->load->view ( 'upload' );
	}
	
	public function up() {
		$config ['upload_path'] = './assets/images/upload/' . date ( 'Ymd' );
		if (! is_dir ( $config ['upload_path'] )) {
			//create the folder if it's not already exists
			mkdir ( $config ['upload_path'], 0777, TRUE );
		}
		$config ['allowed_types'] = 'gif|jpg|png';
		$config ['max_size'] = '2048';
		$config ['max_width'] = '1024';
		$config ['max_height'] = '768';
		$config ['file_name'] = date ( 'YmdHis' );
		
		$this->load->library ( 'upload', $config );
		
		if (! $this->upload->do_upload ( 'file1' )) {
			$data ['error'] = $this->upload->display_errors ();
			$this->load->view ( 'upload', $data );
		} else {
			$data = array ('upload_data' => $this->upload->data () );
			$this->load->view ( 'upload', $data );
		}
	}
}
?>